package com.itheima.service.impl;

import com.itheima.doman.pojo.ClazzOption;
import com.itheima.doman.pojo.JobOption;
import com.itheima.mapper.EmpMapper;
import com.itheima.mapper.StdMapper;
import com.itheima.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

@Service
public class ReportServiceImpl implements ReportService {
    @Autowired
    private EmpMapper empMapper;
    @Autowired
    private StdMapper stdMapper;

    @Override
    @Transactional
    public JobOption reportEmpData() {
        List<Map<String, Object>> list = empMapper.countEmp();
        List<Object> jobList = list.stream().map(map -> map.get("pos")).toList();
        List<Object> dataList = list.stream().map(map -> map.get("num")).toList();
        return new JobOption(jobList, dataList);
    }

    @Override
    @Transactional
    public List<Map> countEmpGender() {
        List<Map> list = empMapper.countEmpGender();
        return list;
    }

    @Override
    public List<Map> countStudentDegree() {
        return stdMapper.countStudentDegree();

    }

    @Override
    public ClazzOption countStudentData() {
        List<Map<String, Object>> list = stdMapper.countStudentData();
        List<Object> calzzList = list.stream().map(map -> map.get("pos")).toList();
        List<Object> dataList = list.stream().map(map -> map.get("num")).toList();
        return new ClazzOption(calzzList, dataList);
    }


}
